package com.jdd.modules.order.service;

import lombok.extern.slf4j.Slf4j;
import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tio.utils.buffer.ByteBufferUtil;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

@Slf4j
@Service
public class MqttClientMsgProcessService {

    @Autowired
    private MqttClientTemplate client;


    public boolean publish() {
        client.publish("/test/client", ByteBuffer.wrap("mica最牛皮".getBytes(StandardCharsets.UTF_8)));
        return true;
    }

    public boolean sub() {
        client.subQos0("/test/#", (context, topic, message, payload) -> {
            log.info(topic + '\t' + ByteBufferUtil.toString(payload));
        });
        return true;
    }

    /**
     * 相机发送过来的消息
     * 有心跳消息
     * 有开/关闸消息
     * @param json
     */
    public void processMsg(String json) {

    }

}
